﻿namespace Singer.Shared.Models;

/// <summary>
/// 统一列表查询结果模型
/// </summary>
/// <typeparam name="T">结果模型</typeparam>
public class QueryResult<T>
{
    /// <summary>
    /// 当前页码
    /// </summary>
    public int PageNo { get; set; }
    /// <summary>
    /// 分页大小
    /// </summary>
    public int PageSize { get; set; }
    /// <summary>
    /// 数据总数
    /// </summary>
    public int TotalCount { get; set; }
    /// <summary>
    /// 总页数
    /// </summary>
    public int PageCount { get; set; }
    /// <summary>
    /// 数据集合
    /// </summary>
    public List<T> List { get; set; } = new List<T>();

    public QueryResult(List<T> list, int pageNo, int pageSize, int totalCount)
    {
        List = list;
        PageNo = pageNo;
        PageSize = pageSize;
        TotalCount = totalCount;
        PageCount = pageSize <= 0 ? 0 : (int)Math.Ceiling((double)totalCount / pageSize);
    }
}
